# conative attitudes  ------------------------------------------------------
# fire_teach
fire_teach_pilot <- ols_main(
  outcome = "fire_teach",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE)


fire_teach_pilot_pvals <- get_RI_pvals(
  outcome = "fire_teach",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE,
  assignment_data = treatment_assignment_pilot,
  extract_function = coef,
  analysis_function = ols_main,
  sims = sims,
  lwr_upr_two = "upr")

pta_pilot <- ols_main(
  outcome = "pta",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE)


pta_pilot_pvals <- get_RI_pvals(
  outcome = "pta",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE,
  assignment_data = treatment_assignment_pilot,
  extract_function = coef,
  analysis_function = ols_main,
  sims = sims,
  lwr_upr_two = "upr")

bring_up_pilot <- ols_main(
  outcome = "bring_up",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE)


bring_up_pilot_pvals <- get_RI_pvals(
  outcome = "bring_up",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE,
  assignment_data = treatment_assignment_pilot,
  extract_function = coef,
  analysis_function = ols_main,
  sims = sims,
  lwr_upr_two = "upr")

assemble_pilot <- ols_main(
  outcome = "assemble",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE)


assemble_pilot_pvals <- get_RI_pvals(
  outcome = "assemble",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE,
  assignment_data = treatment_assignment_pilot,
  extract_function = coef,
  analysis_function = ols_main,
  sims = sims,
  lwr_upr_two = "upr")

absenteeism_action_pilot <- ols_main(
  outcome = "absenteeism_action",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE)

absenteeism_action_pilot_pvals <- get_RI_pvals(
  outcome = "absenteeism_action",
  treatment = "absenteeism",
  resample_FE = TRUE,
  block_FE = TRUE,
  audience_size = TRUE,
  cluster_SE = TRUE,
  covariates = NULL,
  the_data = subset(el_pilot, compliance == 1),
  dosage = FALSE,
  dosage_indicator = FALSE,
  assignment_data = treatment_assignment_pilot,
  extract_function = coef,
  analysis_function = ols_main,
  sims = sims,
  lwr_upr_two = "upr")


#setup
control_means <- with(
  el_pilot, 
  c(
    "Control Mean",
    round(mean(fire_teach[absenteeism == 0 & compliance == 1],na.rm = TRUE), 2),
    round(mean(bring_up[absenteeism == 0 & compliance == 1],na.rm = TRUE), 2),
    round(mean(pta[absenteeism == 0 & compliance == 1],na.rm = TRUE), 2),
    round(mean(assemble[absenteeism == 0 & compliance == 1],na.rm = TRUE), 2),
    round(mean(absenteeism_action[absenteeism == 0 & compliance == 1],na.rm = TRUE), 2)  )
)


pval_lines <- c(
  "RI $p$-values",
  round(fire_teach_pilot_pvals$ri_pvals["absenteeism"],3),
  round(bring_up_pilot_pvals$ri_pvals["absenteeism"],3),
  round(pta_pilot_pvals$ri_pvals["absenteeism"],3),
  round(assemble_pilot_pvals$ri_pvals["absenteeism"],3),
  round(absenteeism_action_pilot_pvals$ri_pvals["absenteeism"],3))

hypothesis_lines <- c(
  "Hypothesis",
  "upr",
  "upr",
  "upr",
  "upr",
  "upr")

#make tables
sink("03_tables/ABS_pilot.tex")
stargazer(
  ... = list(
    fire_teach_pilot$fit,
    bring_up_pilot$fit,
    pta_pilot$fit,
    assemble_pilot$fit,
    absenteeism_action_pilot$fit  ),
  type = "latex",
  p = list(
    fire_teach_pilot$ri_pvals,
    bring_up_pilot$ri_pvals,
    pta_pilot$ri_pvals,
    assemble_pilot$ri_pvals,
    absenteeism_action_pilot$ri_pvals  ),
  se = list(
    fire_teach_pilot$fit_summary[,"Std. Error"],
    bring_up_pilot$fit_summary[,"Std. Error"],
    pta_pilot$fit_summary[,"Std. Error"],
    assemble_pilot$fit_summary[,"Std. Error"],
    absenteeism_action_pilot$fit_summary[,"Std. Error"]  ),
  keep = "absenteeism",
  omit.stat = c("rsq","f","ser"),
  table.layout = "=cd#-t-as=n",
  dep.var.labels = c("Ask headmaster","Tell village","Use PTA","Assemble group","Index"),
  dep.var.labels.include = TRUE,
  no.space = T,
  omit = "block_id",
  add.lines = list(
    control_means,
    pval_lines,
    hypothesis_lines,
    c("Block FE",
      "Yes","Yes","Yes",
      "Yes","Yes")),
  notes.label = "",
  float = FALSE
  # style = "qje"
)
sink()

